<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.9.4"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Flow: flow::Function&lt; Result(Args...)&gt; Class Template Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr id="projectrow">
  <td id="projectalign">
   <div id="projectname">Flow<span id="projectnumber">&#160;2.0.0</span>
   </div>
   <div id="projectbrief">Flow project: Full implementation reference.</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.4 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "search",'Search','.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */
</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="namespaceflow.html">flow</a></li><li class="navelem"><a class="el" href="classflow_1_1Function_3_01Result_07Args_8_8_8_08_4.html">Function&lt; Result(Args...)&gt;</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="summary">
<a href="#pub-types">Public Types</a> &#124;
<a href="#pub-methods">Public Member Functions</a> &#124;
<a href="classflow_1_1Function_3_01Result_07Args_8_8_8_08_4-members.html">List of all members</a>  </div>
  <div class="headertitle"><div class="title">flow::Function&lt; Result(Args...)&gt; Class Template Reference</div></div>
</div><!--header-->
<div class="contents">

<p>Intended as the polymorphic function wrapper of choice for Flow, internally and externally; to be used instead of <code>std::function</code> or <code>boost::function</code>.  
 <a href="classflow_1_1Function_3_01Result_07Args_8_8_8_08_4.html#details">More...</a></p>

<p><code>#include &lt;<a class="el" href="common_8hpp_source.html">common.hpp</a>&gt;</code></p>
<div class="dynheader">
Inheritance diagram for flow::Function&lt; Result(Args...)&gt;:</div>
<div class="dyncontent">
<div class="center"><iframe scrolling="no" frameborder="0" src="classflow_1_1Function_3_01Result_07Args_8_8_8_08_4__inherit__graph.svg" width="156" height="131"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
</div>
<center><span class="legend">[<a href="graph_legend.html">legend</a>]</span></center></div>
<div class="dynheader">
Collaboration diagram for flow::Function&lt; Result(Args...)&gt;:</div>
<div class="dyncontent">
<div class="center"><iframe scrolling="no" frameborder="0" src="classflow_1_1Function_3_01Result_07Args_8_8_8_08_4__coll__graph.svg" width="156" height="131"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
</div>
<center><span class="legend">[<a href="graph_legend.html">legend</a>]</span></center></div>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="pub-types" name="pub-types"></a>
Public Types</h2></td></tr>
<tr class="memitem:ac9d820d29d397987a6a97469f39e367e"><td class="memItemLeft" align="right" valign="top">using&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classflow_1_1Function_3_01Result_07Args_8_8_8_08_4.html#ac9d820d29d397987a6a97469f39e367e">Function_base</a> = std::function&lt; Result(Args...)&gt;</td></tr>
<tr class="memdesc:ac9d820d29d397987a6a97469f39e367e"><td class="mdescLeft">&#160;</td><td class="mdescRight">Short-hand for the base. We add no data of our own in this subclass, just a handful of APIs.  <a href="classflow_1_1Function_3_01Result_07Args_8_8_8_08_4.html#ac9d820d29d397987a6a97469f39e367e">More...</a><br /></td></tr>
<tr class="separator:ac9d820d29d397987a6a97469f39e367e"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="pub-methods" name="pub-methods"></a>
Public Member Functions</h2></td></tr>
<tr class="memitem:a2d28043c36fcccd7d888b7f602678f7e"><td class="memItemLeft" align="right" valign="top"><a class="el" href="classbool.html">bool</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classflow_1_1Function_3_01Result_07Args_8_8_8_08_4.html#a2d28043c36fcccd7d888b7f602678f7e">empty</a> () const noexcept</td></tr>
<tr class="memdesc:a2d28043c36fcccd7d888b7f602678f7e"><td class="mdescLeft">&#160;</td><td class="mdescRight">Returns <code>!bool(*this)</code>; i.e., <code>true</code> if and only if <code>*this</code> has no target.  <a href="classflow_1_1Function_3_01Result_07Args_8_8_8_08_4.html#a2d28043c36fcccd7d888b7f602678f7e">More...</a><br /></td></tr>
<tr class="separator:a2d28043c36fcccd7d888b7f602678f7e"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a1965db8003904aaea686c284b2274057"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classflow_1_1Function_3_01Result_07Args_8_8_8_08_4.html#a1965db8003904aaea686c284b2274057">clear</a> () noexcept</td></tr>
<tr class="memdesc:a1965db8003904aaea686c284b2274057"><td class="mdescLeft">&#160;</td><td class="mdescRight">Makes <code>*this</code> lack any target; i.e., makes it equal to a default-constructed object of this type, so that <code><a class="el" href="classflow_1_1Function_3_01Result_07Args_8_8_8_08_4.html#a2d28043c36fcccd7d888b7f602678f7e" title="Returns !bool(*this); i.e., true if and only if *this has no target.">empty()</a> == true</code> is a post-condition.  <a href="classflow_1_1Function_3_01Result_07Args_8_8_8_08_4.html#a1965db8003904aaea686c284b2274057">More...</a><br /></td></tr>
<tr class="separator:a1965db8003904aaea686c284b2274057"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><div class="compoundTemplParams">template&lt;typename Result, typename... Args&gt;<br />
class flow::Function&lt; Result(Args...)&gt;</div><p >Intended as the polymorphic function wrapper of choice for Flow, internally and externally; to be used instead of <code>std::function</code> or <code>boost::function</code>. </p>
<p >Due to ubiquitous use of such function-object wrappers, this is one of the very few direct non-<code>namespace</code> members of the outer namespace <code><a class="el" href="namespaceflow.html" title="Catch-all namespace for the Flow project: A collection of various production-quality modules written ...">flow</a></code>.</p>
<p >In reality it <em>is</em> <code>std::function</code>, with a couple of added APIs (no data) to make it more similar to <code>boost::function</code> API-wise.</p>
<h3>Rationale</h3>
<p >By far the main reason this exists is: I (ygoldfel) conducted an investigation in 2022, with a not-too-old gcc in Linux, in C++17 mode, with Boost 1.78 (but built seemingly in C++03-supporting config) about the performance behavior of lambdas objects and <code>boost::function&lt;&gt;</code> and <code>std::function&lt;&gt;</code> wrappers thereof. I noticed these things:</p><ul>
<li>Say one constructs a <code>boost::function</code> from a lambda that has 1 or more by-value captures <code>[x = std::move(x)]</code>, with those captures' types having move ctors different and faster than copy ctors. I found that this not only <em>copies</em> each of those captures (invokes their copy ctors), but it even does so several times!<ul>
<li>However, constructing an <code>std::function</code> identically never invokes copy ctors &ndash; only move ctors &ndash; and fewer times at that.</li>
</ul>
</li>
<li>Say one constructs a <code>boost::function</code> from a lambda that has 1 or more by-value captures <code>[x = std::move(x)]</code>, with those captures' types having move ctors but <code>= delete</code>d copy ctors. I.e., say at least 1 capture is movable but not copyable; <code>unique_ptr</code> being a classic and practical example. Well: This does not compile; gcc complains <code>boost::function</code> needs <code>unique_ptr</code> to have a copy ctor, but it is <code>delete</code>d. In the case of <code>unique_ptr</code>, one can do <code>[x = shared_ptr(std::move(x))]</code> to get it work, though it's a bit more code, reduces perf by adding ref-counting, and reduces smart-ptr safety inside the lambda body.<ul>
<li>However, constructing an <code>std::function</code> identically compiles and works fine.</li>
</ul>
</li>
</ul>
<p >So, long story short, at least in that environment, <code>std::function</code> is just plain faster than <code>boost::function</code>, avoiding copying of captures; and it's easier to use with movable-not-copyable capture types.</p>
<p >So we could have just done circa <code>using <a class="el" href="classflow_1_1Function.html">Function</a> = std::function;</code>. Why the subclass? Answer: <code>std::function</code> lacks a couple of commonly used <code>boost::function</code> APIs that code tends to rely on (in the past we used <code>boost::function</code>). These are <a class="el" href="classflow_1_1Function_3_01Result_07Args_8_8_8_08_4.html#a2d28043c36fcccd7d888b7f602678f7e" title="Returns !bool(*this); i.e., true if and only if *this has no target.">empty()</a> and <a class="el" href="classflow_1_1Function_3_01Result_07Args_8_8_8_08_4.html#a1965db8003904aaea686c284b2274057" title="Makes *this lack any target; i.e., makes it equal to a default-constructed object of this type,...">clear()</a> as of this writing. See their doc headers (nothing amazing).</p>
<p >Lastly: In the aforementioned environment, possibly because of having to support C++03 (which lacked param packs) &ndash; unlike <code>std::function</code> which was introduced in C++11 to begin with (and probably conceptually based on <code>boost::function</code>) &ndash; <code>boost::function</code> supports up to 10 args and does not compile when used with 11+ args. <code>std::function</code>, and therefore <a class="el" href="classflow_1_1Function.html">Function</a>, lacks this limitation. It can be used with any number of args.</p>
<dl class="tparams"><dt>Template Parameters</dt><dd>
  <table class="tparams">
    <tr><td class="paramname">Result</td><td>See <code>std::function</code>. </td></tr>
    <tr><td class="paramname">Args</td><td>See <code>std::function</code>. </td></tr>
  </table>
  </dd>
</dl>

<p class="definition">Definition at line <a class="el" href="common_8hpp_source.html#l00559">559</a> of file <a class="el" href="common_8hpp_source.html">common.hpp</a>.</p>
</div><h2 class="groupheader">Member Typedef Documentation</h2>
<a id="ac9d820d29d397987a6a97469f39e367e" name="ac9d820d29d397987a6a97469f39e367e"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ac9d820d29d397987a6a97469f39e367e">&#9670;&nbsp;</a></span>Function_base</h2>

<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename Result , typename... Args&gt; </div>
      <table class="memname">
        <tr>
          <td class="memname">using <a class="el" href="classflow_1_1Function.html">flow::Function</a>&lt; Result(Args...)&gt;::Function_base =  std::function&lt;Result (Args...)&gt;</td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Short-hand for the base. We add no data of our own in this subclass, just a handful of APIs. </p>

<p class="definition">Definition at line <a class="el" href="common_8hpp_source.html#l00566">566</a> of file <a class="el" href="common_8hpp_source.html">common.hpp</a>.</p>

</div>
</div>
<h2 class="groupheader">Member Function Documentation</h2>
<a id="a1965db8003904aaea686c284b2274057" name="a1965db8003904aaea686c284b2274057"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a1965db8003904aaea686c284b2274057">&#9670;&nbsp;</a></span>clear()</h2>

<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename Result , typename... Args&gt; </div>
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">void <a class="el" href="classflow_1_1Function.html">flow::Function</a>&lt; Result(Args...)&gt;::clear</td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">noexcept</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>Makes <code>*this</code> lack any target; i.e., makes it equal to a default-constructed object of this type, so that <code><a class="el" href="classflow_1_1Function_3_01Result_07Args_8_8_8_08_4.html#a2d28043c36fcccd7d888b7f602678f7e" title="Returns !bool(*this); i.e., true if and only if *this has no target.">empty()</a> == true</code> is a post-condition. </p>
<h3>Rationale</h3>
<p >Provided due to ubuiquity of code that uses <code>boost::function::clear()</code> which <code>std::function</code> lacks. </p>

<p class="definition">Definition at line <a class="el" href="common_8hpp_source.html#l00671">671</a> of file <a class="el" href="common_8hpp_source.html">common.hpp</a>.</p>

</div>
</div>
<a id="a2d28043c36fcccd7d888b7f602678f7e" name="a2d28043c36fcccd7d888b7f602678f7e"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a2d28043c36fcccd7d888b7f602678f7e">&#9670;&nbsp;</a></span>empty()</h2>

<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename Result , typename... Args&gt; </div>
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="classbool.html">bool</a> <a class="el" href="classflow_1_1Function.html">flow::Function</a>&lt; Result(Args...)&gt;::empty</td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">noexcept</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>Returns <code>!bool(*this)</code>; i.e., <code>true</code> if and only if <code>*this</code> has no target. </p>
<h3>Rationale</h3>
<p >Provided due to ubuiquity of code that uses <code>boost::function::empty()</code> which <code>std::function</code> lacks.</p>
<dl class="section return"><dt>Returns</dt><dd>See above. </dd></dl>

<p class="definition">Definition at line <a class="el" href="common_8hpp_source.html#l00665">665</a> of file <a class="el" href="common_8hpp_source.html">common.hpp</a>.</p>

</div>
</div>
<hr/>The documentation for this class was generated from the following file:<ul>
<li><a class="el" href="common_8hpp_source.html">common.hpp</a></li>
</ul>
</div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Fri Mar 28 2025 22:55:35 for Flow by&#160;<a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.4
</small></address>
</body>
</html>
